<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('预约列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-primary" onclick="deduction()">
                    <i class="fa fa-calendar"></i> 批量预约
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:record:remove')}]];
        var prefix = ctx + "execution/reservation";
        var cookie = ''
        var money = 100

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "预约",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
                    {
                        field: 'createBy',
                        title: '执行人',
                    },
                    {
                        field: 'mouths',
                        title: '预约月份',
                    },
                    {
                        field: 'days',
                        title: '预约天数',
                    },
                {
                    field: 'reservationNum',
                    title: '预约总人数'
                },
                {
                    field: 'successTotal',
                    title: '预约成功总条数'
                },
                {
                    field: 'failTotal',
                    title: '预约失败总条数'
                },
                    {
                        field: 'createTime',
                        title: '创建时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function deduction() {
            let lock = false
            layer.prompt({title: '请输入预约扣款金额', formType: 3}, function(pass, index) {
                layer.close(index);
                money = pass
                layer.prompt({title: '请输入Cookie', formType: 2}, function (text, index) {
                    layer.close(index);
                    cookie = text.replace(/^\s+|\s+$/g, '')
                    console.log(cookie)
                    lock = true;
                    if (lock) {
                        $.modal.loading("正在批量预约中，请稍后...");
                        $.ajax({
                            url: "/api/index/reservation",
                            type: "post",
                            data: {
                                "cookie": cookie,
                                "Amount": money
                            },
                            success: res => {
                                $.modal.closeLoading();
                                console.log("成功")
                                console.log(res)
                                if (res.code == "200") {
                                    //$.modal.alertSuccess('操作成功！')
                                    $.modal.confirm(res.msg, function () {
                                        $.modal.msgReload("操作成功！正在刷新数据", modal_status.SUCCESS);
                                    });
                                } else if (res.code == "500") {
                                    //$.modal.alertWarning(res.msg)
                                    $.modal.confirm(res.msg, function () {
                                        $.modal.msgReload("正在刷新数据", modal_status.SUCCESS);
                                    });

                                }
                            }
                        })

                    }
                });
            });
        }
    </script>
</body>
</html>